home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / pyshared / GDebi / GDebiCommon.py < prev    next >
Text File  |  2008-08-05  |  6KB  |  160 lines

  1. #!/usr/bin/env python
  2. # Copyright (c) 2005-2007 Canonical
  3. #
  4. # AUTHOR:
  5. # Michael Vogt <mvo@ubuntu.com>
  6. #
  7. # This file is part of GDebi
  8. #
  9. # GDebi is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License as published
  11. # by the Free Software Foundation; either version 2 of the License, or (at
  12. # your option) any later version.
  13. #
  14. # GDebi is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. # General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with GDebi; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22. #
  23.  
  24.  
  25. import sys
  26. import os
  27. import string
  28. import warnings
  29. warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
  30.  
  31. import apt
  32. import apt_pkg
  33.  
  34. from DebPackage import DebPackage, Cache
  35. import gettext
  36.  
  37. #def utf8(str):
  38. #  return unicode(str, 'latin1').encode('utf-8')
  39. def _(str):
  40.     return unicode(gettext.gettext(str), 'UTF-8')
  41.     
  42. def utf8(str):
  43.     if isinstance(str, unicode):
  44.         return str
  45.     return unicode(str, 'UTF-8')
  46.       
  47.       
  48. class GDebiCommon(object):
  49.     # cprogress may be different in child classes
  50.     def __init__(self, datadir, options, file=""):
  51.         self.cprogress = None
  52.         self.deps = ""
  53.         self.version_info_title = ""
  54.         self.version_info_msg = ""
  55.         self._deb = None
  56.          self._options = options
  57.         self.install = []
  58.         self.remove = []
  59.         self.unauthenticated = 0
  60.  
  61.     def openCache(self):
  62.         self._cache = Cache(self.cprogress)
  63.         if self._cache._depcache.BrokenCount > 0:
  64.                 self.error_header = _("Broken dependencies")
  65.                 self.error_body = _("Your system has broken dependencies. "
  66.                              "This application can not continue until "
  67.                              "this is fixed. "
  68.                              "To fix it run 'sudo synaptic' or "
  69.                              "'sudo apt-get install -f' "
  70.                              "in a terminal window.")
  71.         return False
  72.         return True
  73.  
  74.     def open(self, file):
  75.         # open the package
  76.         try:
  77.             self._deb = DebPackage(self._cache, file)
  78.         except (IOError,SystemError),e:
  79.             self.error_header = _("Could not open '%s'" % os.path.basename(file))
  80.             self.error_body = _("The package might be corrupted or you are not "
  81.                          "allowed to open the file. Check the permissions "
  82.                          "of the file.")
  83.             return False
  84.  
  85.     def compareDebWithCache(self):
  86.         # check if the package is available in the normal sources as well
  87.         res = self._deb.compareToVersionInCache(useInstalled=False)
  88.         if not self._options.non_interactive and res != DebPackage.NO_VERSION:
  89.             pkg = self._cache[self._deb.pkgName]
  90.             
  91.             # FIXME: make this strs better, improve the dialog by
  92.             # providing a option to install from repository directly
  93.             # (when possible)
  94.             if res == DebPackage.VERSION_SAME:
  95.                 if self._cache.downloadable(pkg,useCandidate=True):
  96.                     self.version_info_title = _("Same version is available in a software channel")
  97.                     self.version_info_msg = _("You are recommended to install the software "
  98.                             "from the channel instead.")
  99.             elif res == DebPackage.VERSION_IS_NEWER:
  100.                 if self._cache.downloadable(pkg,useCandidate=True):
  101.                     self.version_info_title = _("An older version is available in a software channel")
  102.                     self.version_info_msg = _("Generally you are recommended to install "
  103.                             "the version from the software channel, since "
  104.                             "it is usually better supported.")
  105.             elif res == DebPackage.VERSION_OUTDATED:
  106.                 if self._cache.downloadable(pkg,useCandidate=True):
  107.                     self.version_info_title = _("A later version is available in a software "
  108.                               "channel")
  109.                     self.version_info_msg = _("You are strongly advised to install "
  110.                             "the version from the software channel, since "
  111.                             "it is usually better supported.")
  112.  
  113.     def getChanges(self):
  114.         (self.install, self.remove, self.unauthenticated) = self._deb.requiredChanges
  115.         self.deps = ""
  116.         if len(self.remove) == len(self.install) == 0:
  117.             self.deps = _("All dependencies are satisfied")
  118.         if len(self.remove) > 0:
  119.             # FIXME: use ngettext here
  120.             self.deps += _("Requires the <b>removal</b> of %s packages\n") % len(self.remove)
  121.         if len(self.install) > 0:
  122.             self.deps += _("Requires the installation of %s packages") % len(self.install)
  123.         return True
  124.  
  125.     def try_acquire_lock(self):
  126.         " check if we can lock the apt database "
  127.         try:
  128.             apt_pkg.PkgSystemLock()
  129.         except SystemError:
  130.             self.error_header = _("Only one software management tool is allowed to"
  131.                        " run at the same time")
  132.             self.error_body = _("Please close the other application e.g. 'Update "
  133.                      "Manager', 'aptitude' or 'Synaptic' first.")
  134.             return False
  135.         apt_pkg.PkgSystemUnLock()
  136.         return True
  137.  
  138.     def acquire_lock(self):
  139.         " lock the pkgsystem for install "
  140.         # sanity check ( moved here )
  141.         if self._deb is None:
  142.           return False
  143.  
  144.         # check if we can lock the apt database
  145.         try:
  146.             apt_pkg.PkgSystemLock()
  147.         except SystemError:
  148.             self.error_header = _("Only one software management tool is allowed to"
  149.                                   " run at the same time")
  150.             self.error_body = _("Please close the other application e.g. 'Update "
  151.                                 "Manager', 'aptitude' or 'Synaptic' first.")
  152.             return False
  153.         return True
  154.  
  155.     def release_lock(self):
  156.         " release the pkgsystem lock "
  157.         apt_pkg.PkgSystemLock()
  158.         return True
  159.     
  160.